package com.sdonkey.score.service.impl;

import com.sdonkey.score.bean.AddAdPlaceLimit;
import com.sdonkey.score.dao.AdLimitDao;
import com.sdonkey.score.model.AdPlaceLimitBean;
import com.sdonkey.score.model.AdPlacementLimitListBean;
import com.sdonkey.score.model.FinishPlacementAdBean;
import com.sdonkey.score.service.AdPlaceLimitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service("adPlaceLimitService")
@Transactional
public class AdPlaceLimitServiceImpl implements AdPlaceLimitService {
    @Autowired
    AdLimitDao adLimitDao;
    @Override
    public List<FinishPlacementAdBean> getUnLimitAdList(String advId) {
        return adLimitDao.getUnlimitPlacementAd(advId);
    }

    /**
     * 通过广告id查询
     * @param adId
     * @return
     */
    @Override
    public AdPlaceLimitBean getAdPlacnLimitById(int adId) {
        return adLimitDao.getAdPlacnLimitById(adId);
    }

    @Override
    public int setPlaceLimit(AddAdPlaceLimit addAdPlaceLimit) {
        if(addAdPlaceLimit.getId() != 0){//修改
            adLimitDao.updatePlaceLimitById(addAdPlaceLimit);
        }else{
            //添加
            addAdPlaceLimit.setStatus(1);//默认已开启
            adLimitDao.addPlaceLimit(addAdPlaceLimit);
        }
        int id = addAdPlaceLimit.getId();

        return id;
    }

    @Override
    public List<AdPlacementLimitListBean> getAdPlaceLimitList(String advId) {
        return adLimitDao.getlimitPlacementAdList(advId);
    }
    @Override
    public void deleteAdPlaceLimit(int id){
        adLimitDao.deleteById(id);
    }
}
